/* -----------------
* brief
* 1. this is code gen by tools
 */

package service

import (
	"github.com/mjiulee/lego"
	. "saas_sys_base/modules/eshop/models"
)

type ShopCateService struct {
	// add your model here
	tbShopCate ShopCate
}

func (t *ShopCateService) ListShopCate(keyword string, sort string, page, psize int) ([]map[string]string, int64, error) {
	// 业务查询
	queryMap := map[string]interface{}{
		"table":  map[string]string{"table": "tb_shop_cate", "alias": "t1"},
		"fields": []string{"t1.*"},
		"join":   []map[string]string{
			// map[string]string{"table": "tb_xx as t2", "on": "t2.xid = t1.id"},
		},
		"where": []lego.QMapWhereField{
			{"t1.if_del", "=", 0, "AND", false},
		},
		"search": map[string]string{
			"t1.cate_name": keyword,
		},
		"orders": []string{sort},
		"page": map[string]int{
			"page":  page,
			"psize": psize,
		},
	}
	return lego.QueryListByMap(queryMap)
}

/* 根据id获取记录
 * -----------------
 */
func (t *ShopCateService) GetShopCateById(id int64) *ShopCate {
	return t.tbShopCate.RecodeById(id)
}

/* 添加
 * -----------------
 */
func (t *ShopCateService) SaveShopCate(item2add *ShopCate) bool {
	return t.tbShopCate.AddRecode(item2add)
}

/* 删除(硬删除)*/
func (t *ShopCateService) DelShopCateById(id int64) bool {
	return t.tbShopCate.DelRecodeById(id)
}

/* 更新
 * -----------------*/
func (t *ShopCateService) UpdateShopCate(rc *ShopCate) bool {
	return t.tbShopCate.UpdateRecode(rc)
}

func (t *ShopCateService) GetShopCates() []*ShopCate {
	return t.tbShopCate.GetShopCates()
}
